﻿using GraphProcessor;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ChangeEntityActivation, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ChangeEntityActivation : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ChangeEntityActivation;

        public override string name => LevelEditorConst.ChangeEntityActivation;
        [Output("目标", false)] public EditorLevelServiceDynamicListSetter tagOrMcid;
        [InspectorName("是否激活"), Tooltip("否为取消激活")] public bool isActive;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.ChangeEntityActivation, "EntityAnimAction表ID(激活时动作)")]
        public int animActionId;
        [InspectorName("被激活时改变朝向")] public bool isSetRotation;
        [InspectorName("改变的朝向rotationY")] public int rotationY;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.ChangeEntityActivation, "激活时的位置"), Tooltip("坐标为0则不会变动实体位置")]
        public Vector3 pos;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ChangeEntityActivation()
            {
                isActive = this.isActive,
                animActionId = this.animActionId,
                isSetRotation = this.isSetRotation,
                rotationY = this.rotationY,
                pos = new Int3(this.pos * 100),
                tagOrMcid = LevelServiceDynamicListSelectNode.DefaultParam
            };
            tagOrMcid = new EditorLevelServiceDynamicListSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ChangeEntityActivation rNode)
            {
                this.isActive = rNode.isActive;
                this.animActionId = rNode.animActionId;
                this.isSetRotation = rNode.isSetRotation;
                this.rotationY = rNode.rotationY;
                this.pos = rNode.pos;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ChangeEntityActivation rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}